﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;

namespace WpfCharRain
{
    public static class Config
    {
        public static int Font_Size = 14;
        public static int ScreenWidth = (int)SystemParameters.PrimaryScreenWidth;
        public static int ScreenHeight = (int)SystemParameters.PrimaryScreenHeight;
        public static Brush ForeColor = Brushes.Red;
        public static Brush FirstForeColor = Brushes.White;
        private static Random random = new Random();
        private static int MovingCount = 0;
        public static int TotalCout = Config.ScreenWidth / Config.Font_Size;
        public static Random MovingRandom = new Random();
        public static bool GetIfMoving()
        {
            if(MovingCount<TotalCout/5)
            {
                if (MovingRandom.Next(0, TotalCout) < TotalCout / 5)
                {
                    MovingCount++;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                MovingCount--;
                return false;
            }
        }
        public static int GetSpeed()
        {
            return (int)Math.Sqrt(random.Next(0, 400));
        }
        public static int GetRandom(int start,int end)
        {
            return random.Next(start, end);
        }
        public static string GetGB2312String(int count)
        {
            var bs = new byte[count * 2];
            for (var i = 0; i < count; i++)
            {
                var c = GetGB2312Char(random);
                bs[i * 2] = (byte)(c.X + 0xa0);
                bs[i * 2 + 1] = (byte)(c.Y + 0xa0);
            }
            return Encoding.GetEncoding("GB2312").GetString(bs);
        }

        private static Point GetGB2312Char(Random random)
        {
            // 国标一级字(共3755个): 区:16-55, 位:01-94, 55区最后5位为空位
            var 区 = random.Next(40) + 16;
            var 位 = random.Next(区 == 55 ? 89 : 94) + 1;
            return new Point(区, 位);
        }
    }
}
